//
//  LXMaikeViewController.m
//  bgms_d
//
//  Created by lachesis-zhu on 2019/4/11.
//  Copyright © 2019 lachesis-zhu. All rights reserved.
//

#import "LXMaikeViewController.h"

@interface LXMaikeViewController ()
{
    NSInteger volNumber;
}
@end

@implementation LXMaikeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.warnLabel.numberOfLines = 2;
    self.warnLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volNotication:) name:SOUNDS_CHARACTERISTIC_UUID object:nil];
    [self getVolValue];
}

-(void)volNotication:(NSNotification *)notification
{
    NSData *data = notification.userInfo[kAppHeadUnitData];
    Byte *MessageBt = (Byte *)[data bytes];
    NSInteger type = MessageBt[0];
    if (type == 2) {
        volNumber = MessageBt[2];
        self.volLabel.text = [NSString stringWithFormat:@"%ld", (long)volNumber];
    }
}

- (IBAction)soundReduce:(id)sender {
    if (volNumber >= 1) {
        volNumber -= 1;
        self.volLabel.text = [NSString stringWithFormat:@"%ld", (long)volNumber];
        [self volVulueSend:volNumber];
    }
}

- (IBAction)soundAdd:(id)sender {
    if (volNumber <= 30) {
        volNumber += 1;
        self.volLabel.text = [NSString stringWithFormat:@"%ld", (long)volNumber];
        [self volVulueSend:volNumber];
    }
}

- (void)volVulueSend:(NSInteger)number {
    UInt8 data[3];
    data[0] = 0x02;
    data[1] = number & 0xff;
    data[2] = 0x00;
    [[BLETransDeviceSingleton sharedInstance] characteristc:SOUNDS_CHARACTERISTIC_UUID sendHostCmd:data lenght:3];
}

- (void)getVolValue {
    UInt8 data[3];
    data[0] = 0x01;
    data[1] = 0x01;
    data[2] = 0x00;
    [[BLETransDeviceSingleton sharedInstance] characteristc:COMMON_CHARACTERISTIC_UUID sendHostCmd:data lenght:3];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
